//相关业务逻辑
$(function(){
	page.bind();
});

var page={//页面总变量
		bind:function(){
			$("#login").bind("click",function(){
				var userName=$("#username").val();
				var password=$("#password").val();
				var companyName=$("#companyName").val();
				var weiXinPublicOpenId=$("#weiXinPublicOpenId").val();
				var weiXinPublicunionId=$("#weiXinPublicunionId").val();
				if(userName==""){
					$("#username").attr("placeholder","请输入用户名/手机号");
					return false;
				}
				if(password==""){
					$("#password").attr("placeholder","请输入密码");
					return false;
				}
				if(companyName==""){
					$("#companyName").attr("placeholder","请输公司名称");
					return false;
				}
				var sendDate={
						'company':companyName,
						'userName':userName,
						'password':password,
						'weiXinPublicOpenId':weiXinPublicOpenId,
						'unionId':weiXinPublicunionId
				}
		        $.ajax({
					url:'user/login',
					type:'post',
					data:sendDate,
					dataType:'json',
					success:function(data,status,xhr){
						if(xhr.getResponseHeader("permissionStatus")=='noPermission'){
							layAlert("没有权限");
							return false;
						}
						if(data.result){
							location.href ="success.jsp";
						}else{
							if(data.info!="此微信已关联过其他账号"){
								layAlert(data.info);
							}else{
								layer.confirm(data.info+',是否解绑？', {
								  btn: ['是','否'] //按钮
								}, function(){
									window.location.href = "weiXin/removeBindUser";
								});
							}
						}
					}
				});
			});
			$("#reset").bind("click",function(){
				$("#companyName").val("");
				$("#username").val("");
				$("#password").val("");
			});
		}
}

